Python 使用 tf.range 附加到循环列表

您所在的位置:网站首页 python中for 循环 Python 使用 tf.range 附加到循环列表

Python 使用 tf.range 附加到循环列表

2023-03-11 14:24| 来源: 网络整理| 查看: 265

我正在try 创建一个简单的tf.函数,其中我迭代了一定的次数,每次都追加到一个列表中或在索引处修改它.最近,我try 从range切换到tf.range(),但得到了一些错误.产生错误的两个MRE:

@tf.function def my_function(): outputs = [None for _ in range(10)] for i in tf.range(10): outputs[i] = tf.expand_dims(tf.zeros([10, 10000]), axis=1) return outputs

产 TypeError: list indices must be integers or slices, not Tensor和

@tf.function def my_function(): outputs = [] for _ in tf.range(10): outputs.append(tf.expand_dims(tf.zeros([10, 10000]), axis=1)) return outputs

生产The tensor cannot be accessed from FuncGraph(name=my_function, id=xxxx), because it was defined in FuncGraph(name=while_body_17, id=xxxx), which is out of scope.

如何在避免这些错误的同时保持与列表相同的功能?



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3